package com.moon.game.manager;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.log4j.Logger;

import com.moon.game.resource.model.Npcs;

/**
 * @description NPC管理
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-5-9 下午5:14:53
 */
public class NPCMG {
	private static final Logger log = Logger.getLogger(NPCMG.class);
	public static ConcurrentHashMap<Integer,Npcs> npcs = new ConcurrentHashMap<Integer, Npcs>();

	/**
	 * 根据id获取npc对象
	 * 
	 * @param id
	 * @return
	 */
	public final Npcs getNpcs(int id) {
		return npcs.get(id);
	}

	private NPCMG() {
	}
	public static NPCMG instance = new NPCMG();
	public void init() {
		loadNpcs();
	}
	
	private void loadNpcs() {
		List<Npcs> npcList = DBManager.queryAllNPC();
		for (Npcs npc : npcList) {
			if (npcs.get(npc.getId()) == null) {
				npcs.put(npc.getId(), npc);
			}else {
				log.error("npc id has conflict...");
			}
		}
	}
}
